package com.yunzhong.appointment.system.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yunzhong.appointment.entity.Department;
import com.yunzhong.appointment.entity.Professional;
import com.yunzhong.appointment.mapper.DepartmentMapper;
import com.yunzhong.appointment.mapper.PersonMapper;
import com.yunzhong.appointment.mapper.ProfessionalMapper;
import com.yunzhong.appointment.system.service.ProfessionalService;
import com.yunzhong.appointment.util.PageData;
/**
 * 
 * @className ProfessionalServiceImpl
 * @description 职务模型层接口
 * @author 石洪刚
 * @time 2017年11月15日 下午1:41:52
 */
@Service
public class ProfessionalServiceImpl implements ProfessionalService{

	@Autowired
	private ProfessionalMapper professionalMapper;
	@Autowired
	private DepartmentMapper departmentMapper;
	@Autowired
	private PersonMapper personMapper;
	@Override
	public List<Professional> listProfessional(PageData pd) {
		pd.setPageData(pd);
		System.out.println("pd-----------"+pd);
		return professionalMapper.listProfessional(pd);
	}

	@Override
	public Professional queryProfessionalById(String id) {
		
		return professionalMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<Department> queryDpList() {
		
		return departmentMapper.listDepartment(null);
	}

	@Override
	public Professional judgeProfessionalName(String dpId, String proName) {
		Map m = new HashMap();
		m.put("dpId", dpId);
		m.put("proName", proName);
		return professionalMapper.getProfessionalByDpIdAndProName(m);
	}

	@Override
	public void insertOrUpdate(Professional prof) {
		if("".equals(prof.getProfessionalId())){
			prof.setProfessionalId(UUID.randomUUID().toString());
			professionalMapper.insertSelective(prof);
		}else{
			professionalMapper.updateByPrimaryKeySelective(prof);
		}
	}

	@Override
	public void removeProfessional(String[] ids) {
		for (String id : ids) {
			//将人员中相关信息设置为null
			personMapper.updateProNullByProId(id);
			//删除职务
			professionalMapper.deleteByPrimaryKey(id);
		}
		
	}

}
